package com.jy.api.dao;

import com.jy.api.domain.Inventory;
import com.jy.api.domain.StockReceipt;
import com.jy.api.domain.StockType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;

import java.util.Date;
import java.util.List;


/**
 * Created by xiaohua on 2018/7/5.
 */

public interface InventoryDao extends CrudRepository<Inventory, Long>,QueryByExampleExecutor<Inventory> {

    /**
     * 通过店铺id
     * 首页仓库展示数据
     *
     * @param storeId
     * @param pageable
     * @return
     */
    Page<Inventory> findByStoreIdAndEnabled(String storeId, boolean enable, Pageable pageable);


    @Query(value = "SELECT a.name,pt.name AS typeName,a.quantity FROM product a" + " LEFT JOIN product_type pt on (pt.id= a.product_type_id)" +
            " WHERE pt.name  IS NOT NULL AND a.is_stock_enabled =1 AND a.store_id  =?1", nativeQuery = true)
    List<Object> findByIsStockEnableAndStoreId(String storeId);

    Inventory findById(Long id);


    Page<Inventory> findByEnabledAndProductId(boolean enable,String product, Pageable pageable);

    List<Inventory> findByEnabledAndProductId(boolean enable,String product);

    @Query(value = "select i.id, i.capacity from  inventory i" +
            " where i.product_id=?1 AND enabled=?2 AND store_id=?3  order by capacity ASC ", nativeQuery = true)
    List<Object> findInvByProductId(String productId,boolean enable,String storeId);

    Inventory findByProductIdAndCapacity(String productId, Integer capacity);

    Page<Inventory> findListByEnabledAndStoreId(boolean enable,String id,Pageable pageable);

    List<Inventory> findListByEnabledAndStoreId(boolean enable,String storeId);

    Inventory findByIdAndCapacity(Long id,int cap);

    List<Inventory> findByProductIdAndEnabled(String id,boolean enable);




}
